
package com.mycompany.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "backstage", urlPatterns = {"/backstage"})
public class backstage extends HttpServlet {


 @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
          try {
              processRequest(request, response);
          } catch (Exception ex) {
            Logger.getLogger(backstage.class.getName()).log(Level.SEVERE, null, ex);
          }
    }
    
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, Exception {
        response.setContentType("text/html;charset=UTF-8");
      
       //获取输入的用户名和密码
       String count=request.getParameter("stu_id");
       String password=request.getParameter("password");
       //输入错误仍保留信息
       request.setAttribute("username", count);
       System.out.println("name"+ count +"    code"+ password);
       //String username="liming";
       //String code="1122";
       int result = 0;
      // Sql re=new Sql();
       result = Sql.compl(count, password);
      
       if(result==1){
      // request.setAttribute("cot", count);
      String str1=Sql.show(count);
       request.setAttribute( "cot",str1);
       request.getRequestDispatcher("JSP/suc.jsp").forward(request,response);
       }
       else{
        request.setAttribute("msg", "账号或密码错误，请重新输入");//返回login的错误信息
        request.getRequestDispatcher("JSP/login.jsp").forward(request,response);
       }
    }


}
